package 排序算法;

/*
* 冒泡排序
* */

import 栈.Stack;

public class Bobble {
    static int[] arr1 = {3,5,1,-2,9,8};
    static int[] arr2 = {-2,1,3,5,8,9};
    public static void main(String[] args) {
        BooleSort(arr1);
        print();
    }

    /**
     * 冒泡排序 循环遍历数组,经过一次循环就把最大的数换到后面去
     * @param arr 要被排序的数组
     */
    public static void BooleSort(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - 1 -i; j++) {
                if(arr[j] > arr[j+1]){
                    int tmp = arr[j+1];
                    arr[j+1] = arr[j];
                    arr[j] = tmp;
                }
            }
        }
    }

    public static void print(){
        for (int j : arr1) {
            System.out.print(j + " ");
        }
    }
}
